package com.whlilong.jxc.manager;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.whlilong.jxc.listener.ITextKeyChangeListener;

public class TextKeyManager {
	private static TextKeyManager single = new TextKeyManager();
	private List<ITextKeyChangeListener> listeners = new ArrayList<ITextKeyChangeListener>();

	private TextKeyManager() {

	}

	public static TextKeyManager getInstance() {
		if (single == null)
			single = new TextKeyManager();
		return single;
	}

	public synchronized void addITextKeyChangeListener(
			ITextKeyChangeListener listener) {
		if (!listeners.contains(listener))
			listeners.add(listener);
	}

	public synchronized void removeITextKeyChangeListener(
			ITextKeyChangeListener listener) {
		listeners.remove(listener);
	}
	public synchronized void removeAll() {
		listeners.clear();
	}

	public void notifyListener() {
		for (Iterator<ITextKeyChangeListener> it = listeners.iterator(); it
				.hasNext();) {
			ITextKeyChangeListener listener = it.next();
			listener.changeEvent();
		}
	}

}
